package com.itheima.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 操作员工信息的Mapper
 */
@Mapper
public interface EmpMapper extends BaseMapper<Emp> {
    /**
     * 查询员工信息
     */
    //@Select("select emp.*, dept.name as dept_name from emp left join dept on emp.dept_id = dept.id")
    //public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    //@LogOperator
    public List<Emp> list(EmpQueryParam empQueryParam);

    /**
     * 保存员工信息 - insert
     * 主键返回 --> 获取到插入这条数据的主键.
     */
    // @Options(useGeneratedKeys = true, keyProperty = "id")
    // @Insert("insert into emp(username, name, gender, image, job, entry_date, phone, salary, dept_id, create_time, update_time) " +
    //         "values (#{username}, #{name}, #{gender}, #{image}, #{job}, #{entryDate}, #{phone}, #{salary}, #{deptId}, #{createTime}, #{updateTime})")
    // void insert(Emp emp);

    /**
     * 批量删除员工信息
     */
    void deleteByIds(List<Integer> ids);

    /**
     * 根据id查询员工信息(基本信息, 工作经历信息)
     */
    Emp getById(Integer id);

    /**
     * 根据ID更新员工的基本信息
     */
    // void update(Emp emp);

    /**
     * 统计员工职位人数
     */
    @MapKey("pos")
    List<Map> getEmpJobData();

    /**
     * 统计员工性别
     */
    @MapKey("name")
    List<Map<String, Object>> getEmpGenderData();

    /**
     * 根据部门id查询员工人数
     */
    @Select("select count(*) from emp where dept_id = #{deptId}")
    Integer countByDeptId(Integer deptId);

    /**
     * 查询所有的图像访问路径
     */
    @Select("select distinct image from emp where image != '' and image is not null")
    List<String> listFiles();

    @Select("select * from emp where username=#{username} and password=#{password}")
    Emp findByUserNameAndPwd(Emp emp);



    void updateSalaryById(@Param("ew")LambdaQueryWrapper<Emp> wrapper,
                          @Param("name") int name , @Param("age") int age);

}
